package com.tt.aile.item.service;

import com.tt.aile.item.mapper.SpecParamMapper;
import com.tt.aile.item.pojo.SpecGroup;
import com.tt.aile.item.pojo.SpecParam;
import com.tt.aile.item.pojo.Spu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author 86176 shkstrat
 * @date 2020/10/5 - 16:01
 */
@Service
public class SpecParamService {


    @Autowired
    SpecParamMapper specParamMapper;

    //根据gid查询规格参数（只显示某一项 比如查找手机主体的参数或手机操作系统
    public List<SpecParam> querySpecParamByGid(Long gid) {

        SpecParam specParam = new SpecParam();
        specParam.setGroupId(gid);
        return this.specParamMapper.select(specParam);

    }

    //根据cid查询规格参数（查询所有
    public List<SpecParam> querySpecParamByCid(Long cid) {

        SpecParam specParam = new SpecParam();
        specParam.setCid(cid);
        return this.specParamMapper.select(specParam);

    }

    //根据cid和是否为搜索参数查询规格参数
    public List querySearchParamsByCid(Long cid, Boolean bool) {

        Example example = new Example(SpecParam.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("searching",bool);
        criteria.andEqualTo("cid",cid);

        List<SpecParam> specParams = this.specParamMapper.selectByExample(example);

        return specParams;

    }
}
